//global.proxy_server = 'http://10.0.2.2:5000';
const LocalConfig = require('../localconfig').LocalConfig;
global.proxy_server = LocalConfig.proxy_server_local;
console.log('global.proxy_server from localconfig: ', global.proxy_server);
if (global.proxy_server == undefined) {
  global.proxy_server = 'http://10.0.2.2:5000';
  console.log('use default', global.proxy_server);
}
setGlobalProxyUrls(global.proxy_server);

global.proxyKey = 'STORE_PROXY';
loadData(global.proxyKey).then(data => {
  if (data) {
    console.log('load proxy_server from Storage :', data);
    setGlobalProxyUrls(data);
  }
});

function setGlobalProxyUrls(serverurl) {
  global.proxy_server = serverurl;
  global.proxy_url = global.proxy_server + '/proxy';
  global.proxy_rpc_url = global.proxy_url + '/rpc';
  global.proxy_raw_url = global.proxy_url + '/raw';
  console.log(
    'after setProxyUrls :',
    global.proxy_rpc_url,
    global.proxy_raw_url,
  );
}

global.privateKey =
  '255f01b066a90853a0aa18565653d7b944cd2048c03613a9ff31cb9df9e693e5';

import {loadData} from './storage_utils';
global.userNameKey = 'USER_NAME';
global.username = undefined;

if (global.username == undefined) {
  loadData(global.userNameKey).then(value => {
    console.log('load UserName from storage :', value);
    global.username = value;
  });
}

global.chainId = 'chain0';
global.groupId = 'group0';

global.counter = 0;
module.exports.setProxyUrls = setGlobalProxyUrls;
